package com.ruoyi.web.ydz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.ydz.domain.OtherNews;
import com.ruoyi.web.ydz.service.IOtherNewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 其他新闻Controller
 * 
 * @author Drx
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/ydz/otherNews")
public class OtherNewsController extends BaseController
{
    @Autowired
    private IOtherNewsService otherNewsService;

    /**
     * 查询其他新闻列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:otherNews:list')")
    @GetMapping("/list")
    public TableDataInfo list(OtherNews otherNews)
    {
        startPage();
        List<OtherNews> list = otherNewsService.selectOtherNewsList(otherNews);
        return getDataTable(list);
    }

    /**
     * 导出其他新闻列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:otherNews:export')")
    @Log(title = "其他新闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OtherNews otherNews)
    {
        List<OtherNews> list = otherNewsService.selectOtherNewsList(otherNews);
        ExcelUtil<OtherNews> util = new ExcelUtil<OtherNews>(OtherNews.class);
        util.exportExcel(response, list, "其他新闻数据");
    }

    /**
     * 获取其他新闻详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:otherNews:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(otherNewsService.selectOtherNewsById(id));
    }

    /**
     * 新增其他新闻
     */
    @PreAuthorize("@ss.hasPermi('ydz:otherNews:add')")
    @Log(title = "其他新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OtherNews otherNews)
    {
        return toAjax(otherNewsService.insertOtherNews(otherNews));
    }

    /**
     * 修改其他新闻
     */
    @PreAuthorize("@ss.hasPermi('ydz:otherNews:edit')")
    @Log(title = "其他新闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OtherNews otherNews)
    {
        return toAjax(otherNewsService.updateOtherNews(otherNews));
    }

    /**
     * 删除其他新闻
     */
    @PreAuthorize("@ss.hasPermi('ydz:otherNews:remove')")
    @Log(title = "其他新闻", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(otherNewsService.deleteOtherNewsByIds(ids));
    }

    @PostMapping("/selectOtherNewsByLabel")
    public AjaxResult selectOtherNewsByLabel(@RequestBody OtherNews otherNews) {
        return otherNewsService.selectOtherNewsByLabel(otherNews);
    }

    @GetMapping(value = "/updateOtherNewsHis/{id}")
    public void updateOtherNewsHis(@PathVariable("id") Long id)
    {
        otherNewsService.updateOtherNewsHis(id);
    }
}
